﻿/*
 *	Copyright (c) 2009 Queensland University of Technology. All rights reserved.
 *	The QUT Bioinformatics Collection is open source software released under the 
 *	Microsoft Public License (Ms-PL): http://www.microsoft.com/opensource/licenses.mspx.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

#if ! SILVERLIGHT
using System.Windows.Navigation;
#endif

namespace QUT.Bio.Util {
	/// <summary>
	/// A basic ribbon in which short text messages and a visual distraction
	/// can be displayed.
	/// </summary>

	public partial class StatusBar : UserControl {
		public StatusBar () {
			InitializeComponent();
		}

		/// <summary>
		/// Clears the text display.
		/// </summary>

		public void Clear () {
			statusText.Text = "";
		}

		/// <summary>
		/// Inserts a single line of text, constructed by string.Format, into the display area.
		/// </summary>
		/// <param name="format"></param>
		/// <param name="args"></param>

		public void WriteLine ( string format, params object[] args ) {
			statusText.Text = string.Format( format, args );
		}

		/// <summary>
		/// Sets the visual distraction in motion.
		/// </summary>

		public void StartProgress () {
			twirlyThingContainer.Visibility = Visibility.Visible;
			twirlyThing.Start();
		}

		/// <summary>
		/// Stops the visual distraction.
		/// </summary>

		public void StopProgress () {
			twirlyThing.Stop();
			twirlyThingContainer.Visibility = Visibility.Collapsed;
		}

		/// <summary>
		/// Clears the text display, but can be called by code running outside the GUI thread.
		/// </summary>

		public void ClearAsync () {
#if ! SILVERLIGHT
			Application.Current.Dispatcher.BeginInvoke( new Action( Clear ) );
#else
			Application.Current.RootVisual.Dispatcher.BeginInvoke( new Action( Clear ) );
#endif
		}

		/// <summary>
		/// Inserts a single line of text, constructed by string.Format, into the display area.
		/// for use by code running outside the GUI thread.
		/// </summary>
		/// <param name="format"></param>
		/// <param name="args"></param>

		public void WriteLineAsync ( string format, params object[] args ) {
#if ! SILVERLIGHT
			Application.Current.Dispatcher.BeginInvoke( new Action( delegate() {
				WriteLine( format, args );
			} ) );
#else
			Application.Current.RootVisual.Dispatcher.BeginInvoke( new Action( delegate() {
				WriteLine( format, args );
			} ) );
#endif
		}

		/// <summary>
		/// Sets the visual distraction in motion.
		/// For use by code running outside the GUI thread.
		/// </summary>

		public void StartProgressAsync () {
#if ! SILVERLIGHT
			Application.Current.Dispatcher.BeginInvoke( new Action( StartProgress ) );
#else
			Application.Current.RootVisual.Dispatcher.BeginInvoke( new Action( StartProgress ) );
#endif
		}

		/// <summary>
		/// Stops the visual distraction.
		/// For use by code running outside the GUI thread.
		/// </summary>

		public void StopProgressAsync () {
#if ! SILVERLIGHT
			Application.Current.Dispatcher.BeginInvoke( new Action( StopProgress ) );
#else
			Application.Current.RootVisual.Dispatcher.BeginInvoke( new Action( StopProgress ) );
#endif
		}
	}
}
